// 包含自动生成的绑定
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

use std::ffi::CStr;
use std::ffi::CString;

fn main() {
    // 测试数学函数
    unsafe {
        println!("Math Utilities:");
        println!("10 + 20 = {}", add(10, 20));
        println!("5! = {}", factorial(5));
        println!("Fibonacci(10) = {}", fibonacci(10));
    }

    // 测试字符串函数
    let rust_str = "Hello, C++ from Rust!";
    let c_str = CString::new(rust_str).expect("CString creation failed");
    
    unsafe {
        println!("\nString Utilities:");
        let reversed_ptr = reverse_string(c_str.as_ptr());
        let reversed = CStr::from_ptr(reversed_ptr).to_str().unwrap();
        println!("Original: {}", rust_str);
        println!("Reversed: {}", reversed);
        println!("Length: {}", string_length(c_str.as_ptr()));
        
        // 释放 C++ 分配的内存
        free_string(reversed_ptr);
    }

    // 测试几何函数
    unsafe {
        println!("\nGeometry Utilities:");
        let p1 = create_point(0.0, 0.0);
        let p2 = create_point(3.0, 0.0);
        let p3 = create_point(0.0, 4.0);
        
        println!("Point 1: ({}, {})", p1.x, p1.y);
        println!("Point 2: ({}, {})", p2.x, p2.y);
        println!("Point 3: ({}, {})", p3.x, p3.y);
        
        println!("Distance between p1 and p2: {:.2}", distance(p1, p2));
        println!("Triangle area: {:.2}", triangle_area(p1, p2, p3));
    }
}